# Verify conditions
ping -n 1 -w 1000 8.8.8.8 > /dev/null 2>&1
if [ $? -ne 0 ]; then
    ping -n 1 -w 1000 www.baidu.com > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo Administrator privileges and network connection are required to run this script.
        exit 1
    fi
fi

# Install other software and tools
pacman -Syy
pacman -S --noconfirm unzip unrar make gcc gdb

# Install XTools
XTOOLS_PACKAGE=20211119_XTools4_X86Windows.rar
if [ ! -f $XTOOLS_PACKAGE ]; then
    echo $XTOOLS_PACKAGE not found.
    exit 1
fi

rm -rf /c/x-tools
rm -rf /c/x-tools-headers
mkdir /c/x-tools
mkdir /c/x-tools-headers
fsutil file SetCaseSensitiveInfo /c/x-tools enable
unrar x $XTOOLS_PACKAGE /c/

# Install FFmpeg for development
FFMPEG_PACKAGE=ffmpeg-4.4.2-full_build-shared.zip
if [ ! -f $FFMPEG_PACKAGE ]; then
    echo $FFMPEG_PACKAGE not found.
    exit 1
fi

unzip $FFMPEG_PACKAGE -d /c/Windows/System32/

echo Done.
